home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Temperature / MainWindow.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  8.3 KB  |  415 lines  |  [TEXT/CWIE]

  1. { MainWindow.p }
  2. { Created 10/30/98 12:58 PM by AppMaker }
  3.  
  4. Unit MainWindow;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     Resources,
  16.     TextEdit,
  17.     ToolUtils,
  18.  
  19.     DDocData,
  20.     TemperatureEngine,
  21.     TemperatureDoc,
  22.     AMWindow;
  23.  
  24. type
  25.     MainWindow        = object (AMWindow)
  26.  
  27.     {data members}
  28.         mData:            DDocData;
  29.         mCentigradeLabel:    ControlHandle;
  30.         mEditCentigradeHandle:        ControlHandle;
  31.         mFahrenheitLabel:    ControlHandle;
  32.         mEditFahrenheitHandle:        ControlHandle;
  33.         mCentSliderHandle:        ControlHandle;
  34.         mFahrBarHandle:        ControlHandle;
  35.  
  36.     {methods}
  37.         Procedure Initialize; Override;
  38.  
  39.         Procedure Open        (inDoc:        TemperatureDoc;
  40.                              inData:    DDocData);
  41.         Procedure Close; Override;
  42.  
  43.         Procedure Control    (whichControl:    ControlHandle;
  44.                               whichPart:        integer;
  45.                              where:            Point); Override;
  46.         Procedure MouseIn    (where:            Point;
  47.                              modifiers:        integer); Override;
  48.         Procedure TypeIn    (charCode:        SInt16); Override;
  49.         Procedure ExitCurField; Override;
  50.         Procedure DataChanged    (inDataID:    longint); Override;
  51.         Procedure Resize; Override;
  52.         Procedure Scroll    (newValue:        integer;
  53.                              oldValue:        integer); Override;
  54.  
  55.         Function  GetEngine: TemperatureEngine;
  56.  
  57. {$ifc false}
  58.         Procedure UpdateMenus; Override;
  59. {$endif}
  60.         Function  DoCommand        (inCommand:    longint): Boolean; Override;
  61.  
  62.         Procedure DoUndo;
  63.         Procedure DoCut;
  64.         Procedure DoCopy;
  65.         Procedure DoPaste;
  66.         Procedure DoClear;
  67.         Procedure DoSelectAll;
  68.         Procedure DoShowClipboard;
  69.  
  70.     end;
  71.  
  72. {----------}
  73. Procedure CreateMainWindow    (inDoc:        TemperatureDoc;
  74.                              inData:    DDocData);
  75.  
  76. {----------}
  77. Implementation
  78.  
  79. Uses
  80.     Globals,
  81.     ResourceDefs,
  82.     DoScrap,
  83.     Scrolling,
  84.     ControlUtils,
  85.     Miscellany;
  86.  
  87. const
  88.     kCentigradeLabel        = 1;
  89.     kEditCentigradeField        = 2;
  90.     kFahrenheitLabel        = 3;
  91.     kEditFahrenheitField        = 4;
  92.     kCentSliderScroll        = 5;
  93.     kFahrBarBar            = 6;
  94.  
  95. {----------}
  96. Procedure CreateMainWindow (
  97.     inDoc:        TemperatureDoc;
  98.     inData:        DDocData);
  99. var
  100.     winObj:        MainWindow;
  101. begin
  102.     winObj := nil;
  103.     New (winObj);
  104.  
  105.     if winObj <> nil then begin
  106.         winObj.Initialize;
  107.         winObj.Open (inDoc, inData);
  108.     end;
  109. end;
  110.  
  111. {----------}
  112. Procedure MainWindow.Initialize;
  113. begin
  114.     Inherited Initialize;
  115. end;
  116.  
  117. {----------}
  118. Function  MainWindow.GetEngine: TemperatureEngine;
  119. begin
  120.     GetEngine := TemperatureEngine (mDoc.mEngine);
  121. end;
  122.  
  123. {----------}
  124. Procedure MainWindow.Open (
  125.     inDoc:        TemperatureDoc;
  126.     inData:        DDocData);
  127. var
  128.     window:        WindowPtr;
  129.     wftb:        Handle;
  130.     errCode:    OSErr;
  131. begin
  132.     mDoc := inDoc;
  133.     mData := inData;
  134.     mData.AddResponder (self);
  135.  
  136.     window := GetNewCWindow (WIND_MainWindow, nil, WindowPtr (-1));
  137.     if inDoc.mEngine.GetFilename <> '' then begin
  138.         SetWTitle (window, inDoc.mEngine.GetFilename);
  139.     end;
  140.     mWindow := window;
  141.     TemperatureDoc (mDoc).mMainWindowPtr := window;
  142.  
  143.     WindowPeek (window)^.windowKind := kAMWindowFlag;
  144.     SetWRefCon (window, ord4 (self));
  145.     SetPort (window);
  146.     SetInfo (window);
  147.  
  148.     wftb := GetResource ('Wftb', WIND_MainWindow);
  149.  
  150.     errCode := CreateRootControl (window, mRootControl);
  151.  
  152.     vScroll := nil;
  153.     hScroll := nil;
  154.  
  155.  
  156.     mCentigradeLabel := GetNewControl (CNTL_Centigrade, window);
  157.     SetWindowItemFont (mCentigradeLabel, wftb, 1);
  158.     SetControlFromTEXT (mCentigradeLabel, TEXT_Centigrade);
  159.  
  160.     mEditCentigradeHandle := GetNewControl (CNTL_EditCentigrade, window);
  161.     SetWindowItemFont (mEditCentigradeHandle, wftb, 2);
  162.     SetControlTextValue (mEditCentigradeHandle, mData.GetCentigrade);
  163.  
  164.     mFahrenheitLabel := GetNewControl (CNTL_Fahrenheit, window);
  165.     SetWindowItemFont (mFahrenheitLabel, wftb, 3);
  166.     SetControlFromTEXT (mFahrenheitLabel, TEXT_Fahrenheit);
  167.  
  168.     mEditFahrenheitHandle := GetNewControl (CNTL_EditFahrenheit, window);
  169.     SetWindowItemFont (mEditFahrenheitHandle, wftb, 4);
  170.     SetControlTextValue (mEditFahrenheitHandle, mData.GetFahrenheit);
  171.  
  172.     mCentSliderHandle := GetNewControl (CNTL_CentSlider, window);
  173.     SetWindowItemFont (mCentSliderHandle, wftb, 5);
  174.     SetControlValue (mCentSliderHandle, mData.GetCentigrade);
  175.  
  176.     mFahrBarHandle := GetNewControl (CNTL_FahrBar, window);
  177.     SetWindowItemFont (mFahrBarHandle, wftb, 6);
  178.     SetControlValue (mFahrBarHandle, mData.GetFahrenheit);
  179.  
  180.     errCode := AdvanceKeyboardFocus (window);
  181.  
  182.     ShowWindow (window);
  183. end;
  184.  
  185. {----------}
  186. Procedure MainWindow.Close;
  187. begin
  188.     mData.RemoveResponder (self);
  189.  
  190.     TemperatureDoc (mDoc).mMainWindowPtr := nil;
  191.     SetInfo (nil);
  192.     HideWindow (mWindow);
  193.     DisposeWindow (mWindow);
  194.  
  195.     Dispose (self);
  196. end;
  197.  
  198. {----------}
  199. Procedure MainWindow.Control (
  200.     whichControl:    ControlHandle;
  201.     whichPart:        integer;
  202.     where:            Point);
  203. var
  204.     bounds:            Rect;
  205.     newValue:        integer;
  206.     partcode:        SInt16;
  207. begin
  208.     ExitCurField ();
  209.  
  210.     if whichControl = mEditCentigradeHandle then begin
  211.         HandleEditClick (mEditCentigradeHandle, where);
  212.     end;
  213.     if whichControl = mEditFahrenheitHandle then begin
  214.         HandleEditClick (mEditFahrenheitHandle, where);
  215.     end;
  216.     if whichControl = mCentSliderHandle then begin
  217.         partCode := HandleControlClick (mCentSliderHandle, where, curEvent.modifiers, nil);
  218.         mData.SetCentigrade (GetControlValue (mCentSliderHandle));
  219.     end;
  220. end;
  221.  
  222. {----------}
  223. Procedure MainWindow.DataChanged (
  224.     inDataID:        longint);
  225. begin
  226.     if inDataID = idCentigrade then begin
  227.         SetControlTextValue (mEditCentigradeHandle, mData.GetCentigrade);
  228.     end;
  229.     if inDataID = idFahrenheit then begin
  230.         SetControlTextValue (mEditFahrenheitHandle, mData.GetFahrenheit);
  231.     end;
  232.     if inDataID = idCentigrade then begin
  233.         SetControlValue (mCentSliderHandle, mData.GetCentigrade);
  234.     end;
  235.     if inDataID = idFahrenheit then begin
  236.         SetControlValue (mFahrBarHandle, mData.GetFahrenheit);
  237.     end;
  238. End;
  239.  
  240. {----------}
  241. Procedure MainWindow.MouseIn (
  242.     where:            Point;
  243.     modifiers:        integer);
  244. var
  245.     bounds:            Rect;
  246. begin
  247. end;
  248.  
  249. {----------}
  250. Procedure MainWindow.ExitCurField;
  251. var
  252.     errCode:    OSErr;
  253.     focus:        ControlHandle;
  254. begin
  255.     errCode := GetKeyboardFocus (mWindow, focus);
  256.  
  257.     if focus = nil then begin
  258.         { nothing to exit }
  259.  
  260.     end else if focus = mEditCentigradeHandle then begin
  261.         mData.SetCentigrade (GetControlTextValue (mEditCentigradeHandle));
  262.     end else if focus = mEditFahrenheitHandle then begin
  263.         mData.SetFahrenheit (GetControlTextValue (mEditFahrenheitHandle));
  264.     end;
  265.     inherited ExitCurField;
  266. end;
  267.  
  268. {----------}
  269. Procedure MainWindow.TypeIn (
  270.     charCode:    SInt16);
  271. var
  272.     ch:            char;
  273.     errCode:    OSErr;
  274.     focus:        ControlHandle;
  275.     keyCode:    SInt16;
  276.     partcode:    SInt16;
  277. begin
  278.     errCode := GetKeyboardFocus (mWindow, focus);
  279.  
  280.     ch := chr (charCode);
  281.     if (ch = charEnter)
  282.     |  (ch = charReturn) then begin
  283.         ExitCurField;
  284.     end else if ch = charEsc then begin
  285.     end else if ch = charTab then begin
  286.         DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
  287.     end else if focus <> nil then begin
  288.         keyCode := BAnd (curEvent.message, keyCodeMask);
  289.         partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
  290.         mDoc.mEngine.SetDirty;
  291.     end else begin
  292.         SysBeep (1);
  293.     end;
  294. end;
  295.  
  296. {----------}
  297. Procedure MainWindow.Resize;
  298. begin
  299.     { application-specific code to resize items in window }
  300. end;
  301.  
  302. {----------}
  303. Procedure MainWindow.Scroll (
  304.     newValue:    integer;
  305.     oldValue:    integer);
  306. begin
  307.     { application-specific code to scroll window }
  308.     if gWhichScroll = vScroll then begin
  309.     end else begin    { horizontal }
  310.     end;
  311. end;
  312.  
  313. {----------}
  314. Procedure MainWindow.DoUndo;
  315. begin
  316. end; {DoUndo}
  317.  
  318. {----------}
  319. Procedure MainWindow.DoCut;
  320. var
  321.     curTE:        TEHandle;
  322. begin
  323.     curTE := GetCurTE ();
  324.  
  325.     if curTE <> nil then begin
  326.         TECut (curTE);
  327.         mDoc.mEngine.SetDirty;
  328.         scrapDirty := true;
  329.     end;
  330. end; {DoCut}
  331.  
  332. {----------}
  333. Procedure MainWindow.DoCopy;
  334. var
  335.     curTE:        TEHandle;
  336. begin
  337.     curTE := GetCurTE ();
  338.  
  339.     if curTE <> nil then begin
  340.         TECopy (curTE);
  341.         scrapDirty := true;
  342.     end;
  343. end; {DoCopy}
  344.  
  345. {----------}
  346. Procedure MainWindow.DoPaste;
  347. var
  348.     curTE:        TEHandle;
  349. begin
  350.     curTE := GetCurTE ();
  351.  
  352.     if curTE <> nil then begin
  353.         TEPaste (curTE);
  354.         mDoc.mEngine.SetDirty;
  355.     end;
  356. end; {DoPaste}
  357.  
  358. {----------}
  359. Procedure MainWindow.DoClear;
  360. var
  361.     curTE:        TEHandle;
  362. begin
  363.     curTE := GetCurTE ();
  364.  
  365.     if curTE <> nil then begin
  366.         TEDelete (curTE);
  367.         mDoc.mEngine.SetDirty;
  368.     end;
  369. end; {DoClear}
  370.  
  371. {----------}
  372. Procedure MainWindow.DoSelectAll;
  373. var
  374.     curTE:        TEHandle;
  375. begin
  376.     curTE := GetCurTE ();
  377.  
  378.     if curTE <> nil then begin
  379.         TESetSelect (0, 32767, curTE);
  380.     end;
  381. end; {DoSelectAll}
  382.  
  383. {----------}
  384. Procedure MainWindow.DoShowClipboard;
  385. begin
  386. end; {DoShowClipboard}
  387.  
  388. {----------}
  389. Function MainWindow.DoCommand (
  390.     inCommand:        longint): Boolean;
  391. begin
  392.     DoCommand := true;
  393.     case inCommand of
  394.         cmdUndo:
  395.                 DoUndo;
  396.         cmdCut:
  397.                 DoCut;
  398.         cmdCopy:
  399.                 DoCopy;
  400.         cmdPaste:
  401.                 DoPaste;
  402.         cmdClear:
  403.                 DoClear;
  404.         cmdSelectAll:
  405.                 DoSelectAll;
  406.         cmdShowClipboard:
  407.                 DoShowClipboard;
  408.  
  409.         otherwise
  410.                 DoCommand := false;
  411.     end; {case}
  412. end;
  413.  
  414. end.
  415.